package com.hqyj.controller;

import com.hqyj.pojo.Customer;
import com.hqyj.pojo.Manager;
import com.hqyj.service.CustomerService;
import com.hqyj.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Controller
@RequestMapping("/login")
public class loginController {
    @Autowired
    CustomerService customerService;
    @Autowired
    ManagerService managerService;
    @RequestMapping("loginPage")
    public String login(){
        return "login1";
    }
    @RequestMapping("/customerLogin")
    public String customerLogin(){return "customerLogin";}
    @RequestMapping("/cloginAjax")//客户登录
    @ResponseBody
    public HashMap<String, Object> cloginAjax(Customer customer, HttpServletRequest request)
    {
        System.out.println(customer.getName()+customer.getPwd()+customer.getCode());
        HashMap<String, Object> map = new HashMap();
        String info = customerService.login(customer,request);
        HttpSession session = request.getSession();
        map.put("info",info);
        session.setAttribute("state","customer");
        return map;
    }
    @RequestMapping("/mloginAjax")//经理登录
    @ResponseBody
    public HashMap<String, Object> mloginAjax(Manager manager, HttpServletRequest request)
    {

        HashMap<String, Object> map1 = new HashMap();
        String info = managerService.login(manager,request);
        HttpSession session = request.getSession();
        map1.put("info",info);
        session.setAttribute("state","manager");
        return map1;
    }
    @RequestMapping("/csendEmail")
    @ResponseBody
    public HashMap<String, Object> sendEmail(Customer customer, HttpServletRequest request){
        return customerService.sendCode(customer,request);
    }
    @RequestMapping("/msendEmail")
    @ResponseBody
    public HashMap<String, Object> sendEmail(Manager manager, HttpServletRequest request){
        return managerService.sendCode(manager,request);
    }
}
